<template>
  <div class="banner-center">
    <el-carousel :height="height" indicator-position="none" :arrow="arrows" :interval="2000">
      <el-carousel-item v-for="(item, index) in url" :key="index">
        <el-image
          style="width: 100%; height: 100%"
          :src="item.pic ? baseURL + item.pic : item.url"
          fit="cover"
          @click="handlePath(item[keyName])"
        />
      </el-carousel-item>
    </el-carousel>
  </div>
</template>
<script lang="ts" setup>
const props = defineProps({
  // 	切换箭头
  arrows: {
    type: String,
    default: "always",
  },
  // 高度
  height: {
    type: String,
    default: "472px",
  },
  // 图片列表
  url: {
    type: Array,
    default: () => [],
  },
  // 开启跳转
  router: {
    type: Boolean,
    default: false,
  },
  // 跳转所需要键名字段
  keyName: {
    type: String,
    default: "jumpUrl",
  },
});
const baseURL = import.meta.env.VITE_BASE_URL;

// 跳转网址
const handlePath = (path: string) => {
  if (props.router) {
    location.href = path;
  }
};
</script>
<style lang="less" scoped>
.banner-center {
  overflow: hidden;
  z-index: -1;
}
</style>
